<template>
  <div class="detail">
    <div class="m-h3-btn-box border">
      <h3>基本信息</h3>
      <div class="u-btn-box">
        <el-button type="primary" @click="save()" size="small">
          {{ isSave ? '保存' : '编辑' }}</el-button
        >
      </div>
    </div>
    <el-form
      :model="detail"
      label-width="120px"
      label-position="left"
      :rules="formRules"
      ref="detailForm"
    >
      <el-row :gutter="40">
        <el-col :span="8">
          <el-form-item label="" prop="head_url">
            <el-upload
              class="avatar-uploader"
              :action="url"
              :show-file-list="false"
              :http-request="uploadImg"
              :before-upload="beforeAvatarUpload"
            >
              <img
                v-if="detail.head_url"
                :src="detail.head_url"
                class="avatar"
              />
              <span
                class="el-upload-list__item-delete"
                @click.stop="handleRemove()"
                v-if="detail.head_url"
                >x</span
              >
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-row :gutter="30">
            <el-col :span="9">
              <el-form-item label="姓名：" prop="name">
                <el-input
                  v-model="detail.name"
                  :disabled="!isSave"
                  placeholder="请输入姓名"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="9">
              <el-form-item label="性别：" prop="sex">
                <el-select
                  v-model="detail.sex"
                  placeholder="请选择性别"
                  :disabled="!isSave"
                  clearable
                >
                  <el-option label="男" :value="0"></el-option>
                  <el-option label="女" :value="1"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="30">
            <el-col :span="9">
              <el-form-item label="生日：" prop="birth_date">
                <el-date-picker
                  v-model="detail.birth_date"
                  type="date"
                  placeholder="请选择生日"
                  class="date-picker"
                  :disabled="!isSave"
                  clearable
                  value-format="yyyy-MM-dd"
                  format="yyyy-MM-dd"
                  :picker-options="pickerOptions"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="9">
              <el-form-item label="年龄：" prop="age">
                <el-input
                  v-model="detail.age"
                  disabled
                  placeholder="请输入年龄"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="30">
            <el-col :span="9">
              <el-form-item label="线下学校：" prop="school_id">
                <el-select
                  v-model="detail.school_id"
                  filterable
                  remote
                  reserve-keyword
                  placeholder="请选择线下学校"
                  :remote-method="getOfflineSchool"
                  :loading="loading"
                  :disabled="!isSave"
                  @change="handleSchoolChange"
                  clearable
                >
                  <el-option
                    v-for="item in offlineSchool"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="9">
              <el-form-item label="线下班级：" prop="school_class_name">
                <el-cascader
                  v-model="detail.school_class_name"
                  :options="gradeList"
                  @active-item-change="changeHandle"
                  placeholder="请选择线下班级"
                  :disabled="!isSave || !detail.school_id"
                  clearable
                ></el-cascader>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row
            :gutter="30"
            v-for="(item, index) in detail.contract"
            :key="index"
          >
            <el-col :span="9">
              <el-form-item label="联系人：" prop="contract">
                <el-input
                  v-model="item.contract"
                  :disabled="!isSave"
                  placeholder="请输入联系人"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="9">
              <el-form-item
                label="联系方式："
                :prop="'contract.' + index + '.phone'"
                v-if="isSave"
                :rules="[
                  {
                    required: true,
                    message: '联系方式不能为空',
                    trigger: 'blur'
                  },
                  { validator: validateMobile, trigger: 'blur' }
                ]"
              >
                <el-input
                  v-model="item.phone"
                  placeholder="请输入联系方式"
                  clearable
                ></el-input>
              </el-form-item>
              <el-form-item label="联系方式：" v-else>
                <el-input
                  v-model="item.hidePhone"
                  disabled
                  placeholder="请输入联系方式"
                  clearable
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3" class="margin-top10">
              <el-radio
                v-model="currentValue"
                :label="item.id"
                :disabled="!isSave"
              >
                <span v-if="currentValue === item.id">默认</span>
                <span v-else></span>
              </el-radio>
            </el-col>
            <el-col :span="3" class="margin-top10" v-if="isSave">
              <i
                class="el-icon-delete"
                @click="deleteContract(item, index)"
                v-if="index !== 0"
              ></i>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="20" class="center margin-top-20 margin-bottom10">
              <el-button
                type="text"
                icon="el-icon-circle-plus"
                size="small"
                @click="addContract()"
                v-if="isSave"
                >新增联系人</el-button
              >
            </el-col>
          </el-row>
          <el-row :gutter="30">
            <el-col :span="9">
              <el-form-item label="邮寄住址：" prop="address">
                <el-input
                  v-model="detail.address"
                  :disabled="!isSave"
                  placeholder="请输入邮寄地址"
                  clearable
                  maxlength="50"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="9">
              <h4>
                <span
                  >来源：{{
                    $filterEnums(
                      detail.source,
                      this.selectEnums.nice_student.source
                    )
                  }}</span
                >
                <!-- <span class="margin-left20">状态：{{$filterEnums(detail.status, this.selectEnums.nice_student.status)}}</span> -->
              </h4>
            </el-col>
          </el-row>
          <el-row>
            <span>账号：{{ $hidePhone(detail.account) }}</span>
            <el-button
              type="primary"
              @click="reset()"
              size="small"
              class="margin-left20"
              :disabled="!isSave"
              >重置密码</el-button
            >
          </el-row>
        </el-col>
      </el-row>
    </el-form>
    <div class="m-h3-btn-box border">
      <h3>学习经历</h3>
      <div class="u-btn-box">
        <el-button type="primary" @click="applyHandle()" size="small"
          >报名</el-button
        >
      </div>
    </div>
    <nice-table
      :data="studyList"
      :showIndex="true"
      :columns="studyTable"
      :pagination="studyPagination"
      :showBorder="false"
    >
      <el-table-column
        label="操作"
        align="center"
        width="200"
        slot="opreation"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="small"
            type="text"
            @click="adjustDateHandle(scope.row)"
            :disabled="scope.row.complete_num === scope.row.total_num"
            >调期</el-button
          >
        </template>
      </el-table-column>
    </nice-table>
    <div class="border"><h3>订单信息</h3></div>
    <nice-table
      :data="orderList"
      :columns="orderTable"
      :pagination="orderPagination"
      :showBorder="false"
    ></nice-table>
    <div class="border"><h3>积分订单</h3></div>
    <nice-table
      :data="orderList1"
      :columns="orderTable1"
      :pagination="orderCodePagination"
      :showBorder="false"
    ></nice-table>
    <!--调期-->
    <adjust-date
      v-if="adjustDateVisible"
      ref="adjustDate"
      @refreshDataList="getLearningExperience"
    ></adjust-date>
    <!--新增联系人-->
    <add-contract
      v-if="addContractVisible"
      ref="addContract"
      @refreshDataList="getStudentDetail"
    ></add-contract>
    <batch-apply
      v-if="applyVisible"
      ref="applyForm"
      @refreshDataList="getDataList"
      :applyWay="applyWay"
      :multipleSelection="multipleSelection"
    ></batch-apply>
  </div>
</template>
<script>
import AdjustDate from './adjust-date'
import AddContract from './add-contract'
import BatchApply from '../school-list/batch-apply'
import {
  ossUpload,
  tableUpdate,
  tableDeleted,
  cascadeQuery
} from '@/api/api.js'
import {
  getStudentDetailById,
  queryPageList,
  getLearningExperience,
  getOrderListById,
  getGrade
} from '@/api/user.js'
import { myEnumsMixins } from '@/utils/mixins'
import { getStudentOrderList } from '@/api/order.js'
export default {
  name: 'student-detail',
  components: {
    AdjustDate,
    AddContract,
    BatchApply
  },
  mixins: [myEnumsMixins],
  data () {
    return {
      pickerOptions: {
        disabledDate (time) {
          return time.getTime() > Date.now()
        }
      },
      coverGradeList: [],
      multipleSelection: [],
      applyVisible: false,
      applyWay: '',
      detail: {
        head_url: '', // 头像
        name: '', // 姓名
        age: '',
        sex: '',
        birth_date: '',
        address: '',
        source: '', // 来源
        school_id: '', // 线下学校
        school_class_name: '', // 线下班级
        contract: [],
        status: '',
        account: ''
      },
      orderOptions: [
        { label: '已付款', value: 1 },
        { label: '已发货', value: 2 }
        // {label:'未付金币',value:0},
        // {label:'已付金币未发货',value:1},
        // {label:'发货',value:2},
        // {label:'收货',value:3},
        // {label:'退款中',value:4},
        // {label:'退款完成',value:5},
        // {label:'交易完成',value:6},
      ],
      addContractVisible: false,
      url: '',
      userId: '',
      mobile: '',
      offlineSchool: [],
      gradeList: [],
      loading: false,
      dialogVisible: false,
      isSave: false,
      currentValue: 0,
      studyList: [],
      orderList: [],
      orderList1: [],
      formRules: {
        name: [
          { required: true, message: '姓名不能为空', trigger: 'blur' },
          { min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur' }
        ]
      },
      orderCodePagination: {
        total: 0,
        pageNum: 1,
        pageSize: 10,
        handleCurrentChange: this.handleOrderCurrentChange1,
        handleSizeChange: this.handleOrderSizeChange1
      },
      adjustDateVisible: false,
      studyPagination: {
        total: 0,
        pageNum: 1,
        pageSize: 10,
        handleCurrentChange: this.handleStudyCurrentChange,
        handleSizeChange: this.handleStudySizeChange
      },
      orderPagination: {
        total: 0,
        pageNum: 1,
        pageSize: 10,
        handleCurrentChange: this.handleOrderCurrentChange,
        handleSizeChange: this.handleOrderSizeChange
      },
      studyTable: [
        {
          label: '课程名称',
          prop: 'name',
          width: '200'
        },
        {
          label: '状态',
          prop: 'status',
          width: '80'
        },
        {
          label: '期次',
          prop: 'sort'
        },
        {
          label: '上课时间',
          prop: 'periodTime',
          width: '500'
        },
        {
          label: '已完成（讲次）',
          prop: 'complete',
          width: '180'
        },
        {
          label: '主讲老师',
          prop: 'teacher_name'
        },
        {
          label: '辅导老师',
          prop: 'tutor'
        },
        {
          label: '所属班级',
          prop: 'classes_name'
        }
      ],
      orderTable: [
        {
          label: '订单编号',
          prop: 'order_number',
          fixed: 'left',
          extends: [
            {
              clickFunction: val => {
                this.viewOrderDetail(val)
              }
            }
          ]
        },
        {
          label: '支付金额',
          prop: 'pay_amount',
          width: '80'
        },
        {
          label: '订单金额',
          prop: 'order_amount',
          width: '80'
        },
        {
          label: '商品名称',
          prop: 'goods_name'
        },
        {
          label: '商品类型',
          prop: 'goods_type',
          width: '80'
        },
        {
          label: '订单状态',
          prop: 'status',
          width: '80',
          extends: [
            {
              filterFunction: val => {
                return this.$filterEnums(
                  val,
                  this.selectEnums.nice_order.status,
                  'real_value'
                )
              }
            }
          ]
        },
        {
          label: '付款时间',
          prop: 'success_time'
        },
        {
          label: '支付方式',
          prop: 'pay_way',
          width: '80',
          fixed: 'right',
          extends: [
            {
              filterFunction: val => {
                return this.$filterEnums(
                  val,
                  this.selectEnums.nice_pay_info.pay_way,
                  'real_value'
                )
              }
            }
          ]
        }
      ],
      orderTable1: [
        {
          label: '订单编号',
          prop: 'id',
          fixed: 'left',
          extends: [
            {
              clickFunction: val => {
                this.viewIntegralOrderDetail(val)
              }
            }
          ]
        },
        {
          label: '订单金额(币)',
          prop: 'coinsCount'
        },
        {
          label: '商品名称',
          prop: 'goodsName'
        },
        {
          label: '商品数量',
          prop: 'goodsCount'
        },
        {
          label: '订单状态',
          prop: 'orderStatus',
          extends: [
            {
              filterFunction: val => {
                return this.$fliterStatus(val, this.orderOptions)
              }
            }
          ]
        },
        {
          label: '兑换时间',
          prop: 'createTime'
        }
      ]
    }
  },
  activated () {
    this.url = this.$http.adornUrl(
      `/questionlib/sys/oss/upload?token=${this.$cookie.get('token')}`
    )
    this.userId = this.$route.params.id
    this.isSave = false
    this.getStudentDetail()
    this.getLearningExperience()
    this.getOrderListById()
    this.getIntegralOrderListById()
  },
  watch: {
    'detail.birth_date' (val) {
      this.detail.age = val
        ? this.$age(this.$formatDate(val, 'yyyy-MM-dd'))
        : ''
    }
  },
  methods: {
    getDataList () {
      this.getLearningExperience()
      this.getOrderListById()
    },
    $fliterStatus (val, data) {
      let label = ''
      data.forEach(ele => {
        if (ele.value == val) {
          label = ele.label
        }
      })
      return label
    },
    async getIntegralOrderListById () {
      let res = await getStudentOrderList({
        pageIndex: this.orderCodePagination.pageNum,
        pageSize: this.orderCodePagination.pageSize,
        id: this.userId
      })
      if (res[0]) {
        return
      }
      if (res[1].code == 0) {
        this.orderList1 = res[1].userOrderList
        this.orderCodePagination.total = res[1].orderCount
      }
    },
    async getStudentDetail () {
      this.gradeList = []
      let res = await getStudentDetailById({
        'nice_student.user_id': this.userId
      })
      if (res[0]) {
        return
      }
      let data = res[1]
      if (data && data.code === 0) {
        if (data.data.contact) {
          data.data.contract = data.data.contact
            .split(',')
            .map((ele, index) => {
              let arr = ele.split('-')
              let contract =
                arr[0].replace(/(^\s*)|(\s*$)/g, '') === 'NULL'
                  ? ''
                  : arr[0].replace(/(^\s*)|(\s*$)/g, '')
              return {
                contract: contract,
                phone: arr[1],
                id: index + 10,
                is_default: arr[2] || '',
                hidePhone: this.$hidePhone(arr[1])
              }
            })
          let defaultArr = data.data.contract.filter(ele => {
            return ele.is_default === '1'
          })
          this.currentValue =
            defaultArr && defaultArr.length
              ? defaultArr[0].id
              : data.data.contract[0].id
        }
        if (data.data) {
          this.$refs['detailForm'].clearValidate()
          this.detail = data.data
          this.detail.school_class_id &&
            this.gradeList.push({
              label: this.detail.school_class_name,
              value: this.detail.school_class_id
            })
          this.detail.school_class_name = [this.detail.school_class_id]
          this.detail.age = this.detail.birth_date
            ? this.$age(this.$formatDate(this.detail.birth_date, 'yyyy-MM-dd'))
            : ''
          this.detail.sex = this.detail.sex === 2 ? '' : this.detail.sex
          this.getOfflineSchool(this.detail.school_name)
        }
      } else {
        this.$message.error(data.msg)
      }
    },
    async getLearningExperience () {
      let res = await getLearningExperience({
        'nice_course_period_student.student_id': this.userId,
        'page.currPage': this.studyPagination.pageNum,
        'page.pageSize': this.studyPagination.pageSize
      })
      if (res[0]) {
        return
      }
      let data = res[1]
      if (data && data.code === 0) {
        this.studyPagination.total = data.data.pageList.totalCount
        this.studyList = data.data.pageList.list
        this.studyList.forEach(ele => {
          let frequency = JSON.parse(ele.frequency)
          let week = '周' + this.$filterFrequency(frequency)
          ele.periodTime =
            ele.start_date.substring(0, 10) +
            '-' +
            ele.end_date.substring(0, 10) +
            week
          ele.complete = ele.complete_num + '/' + ele.total_num
          ele.sort = '第' + this.$convertNum(ele.sort) + '期'
          ele.status = ele.complete_num === ele.total_num ? '已结课' : '学习中'
        })
      } else {
        this.$message.error(data.msg)
      }
    },
    async getOrderListById () {
      let res = await getOrderListById({
        'nice_order.user_id': this.userId,
        'page.currPage': this.orderPagination.pageNum,
        'page.pageSize': this.orderPagination.pageSize
      })
      if (res[0]) {
        return
      }
      let data = res[1]
      if (data && data.code === 0) {
        this.orderPagination.total = data.data.pageList.totalCount
        this.orderList = data.data.pageList.list
        if (this.orderList && this.orderList.length) {
          this.orderList.forEach(ele => {
            ele.goods_type = '课程'
            ele.status = JSON.stringify(ele.status)
          })
        }
      } else {
        this.$message.error(data.msg)
      }
    },
    async getGrade () {
      this.gradeList = []
      let res = await getGrade({ grade: this.coverGradeList })
      if (res[0]) {
        return
      }
      if (res[1] && res[1].code === 0) {
        res[1].data.forEach(ele => {
          this.gradeList.push({
            label: ele.display_value,
            value: ele.t_id,
            children: []
          })
        })
      }
    },
    async saveContract () {
      this.detail.contract.forEach(ele => {
        ele.is_default = ele.id === this.currentValue ? 1 : 0
        if (ele.is_default) {
          this.mobile = ele.phone
        }
      })
      let contractList = this.detail.contract.map(ele => {
        return {
          table_name: 'nice_student_contacts',
          update: [
            {
              contacts: ele.contract,
              contacts_mobile: ele.phone,
              is_default: ele.is_default
            }
          ],
          where: [
            {
              id: ele.id
            }
          ]
        }
      })
      let res = await tableUpdate(contractList)
      if (res[0]) {
        return
      }
      let data = res[1]
      if (data && data.code === 0) {
        this.submit()
      } else {
        this.$message.error(data.msg)
      }
    },
    applyHandle () {
      this.applyVisible = true
      this.applyWay = 'single'
      this.$nextTick(() => {
        this.$refs.applyForm.init(this.userId)
      })
    },
    async getOfflineSchool (query) {
      if (query !== '') {
        this.loading = true
        let form = {
          table_name: 'nice_school',
          'nice_school.school_name': query
        }
        let res = await queryPageList(form)
        if (res[0]) {
          return
        }
        let data = res[1]
        this.loading = false
        if (data && data.code === 0) {
          if (
            data.data.pageList &&
            data.data.pageList.list &&
            data.data.pageList.list.length
          ) {
            this.offlineSchool = data.data.pageList.list.map(item => {
              return {
                label: item.school_name,
                value: item.id,
                nursery_grade: item.nursery_grade,
                junior_grade: item.junior_grade,
                middle_grade: item.middle_grade,
                high_grade: item.high_grade
              }
            })
          } else {
            this.offlineSchool = []
          }
        }
      }
    },
    async changeHandle (val) {
      let res = await cascadeQuery({
        table_name: 'nice_school_classes',
        condition: {
          school_id: this.detail.school_id,
          init_grade: val[0]
        }
      })
      if (res[0]) {
        return
      }
      if (res[1] && res[1].code === 0) {
        this.gradeList.forEach(ele => {
          if (ele.value === val[0]) {
            ele.children = res[1].data.map(item => {
              return { label: item.class_name, value: item.id }
            })
          }
        })
      } else {
        this.$message.error(res[1].msg)
      }
    },
    handleSchoolChange (val) {
      this.gradeList = []
      this.detail.school_class_name = []
      if (this.detail.school_id) {
        let coveragegrade =
          this.offlineSchool &&
          this.offlineSchool.filter(ele => {
            return ele.value === this.detail.school_id
          })[0]
        this.coverGradeList = []
        this.selectEnums.nice_school.coverage_grade.forEach(ele => {
          coveragegrade.nursery_grade &&
            ele.label === '幼儿园' &&
            this.coverGradeList.push(ele.value)
          coveragegrade.junior_grade &&
            ele.label === '小学' &&
            this.coverGradeList.push(ele.value)
          coveragegrade.middle_grade &&
            ele.label === '初中' &&
            this.coverGradeList.push(ele.value)
          coveragegrade.high_grade &&
            ele.label === '高中' &&
            this.coverGradeList.push(ele.value)
        })
        this.getGrade()
      }
    },
    save () {
      if (this.isSave) {
        this.$refs['detailForm'].validate(valid => {
          if (valid) {
            if (this.detail.contract && this.detail.contract.length) {
              this.saveContract()
            } else {
              this.submit()
            }
          }
        })
      } else {
        this.isSave = true
      }
    },
    async submit () {
      console.log(333, this.detail.school_id)
      let res = await tableUpdate([
        {
          table_name: 'nice_user_base',
          update: [
            {
              real_name: this.detail.name,
              sex: this.detail.sex,
              //  'mobile': this.mobile,
              birth_date: this.detail.birth_date,
              address: this.detail.address,
              head_url: this.detail.head_url,
              nice_user_base_nice_student: [
                {
                  school_id: this.detail.school_id,
                  grade: this.detail.school_class_name
                    ? this.detail.school_class_name[0]
                    : '',
                  school_class_id: this.detail.school_class_name
                    ? this.detail.school_class_name[1]
                    : ''
                }
              ]
            }
          ],
          where: [
            {
              sys_user_id: this.userId
            }
          ]
        }
      ])
      if (res[0]) {
        return
      }
      let data = res[1]
      if (data && data.code === 0) {
        this.$message.success('保存成功')
        this.getStudentDetail()
        this.isSave = false
      }
    },
    reset () {
      this.$confirm('确定进行重置操作？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.resetPassword()
        })
        .catch(() => {})
    },
    async resetPassword () {
      let res = await tableUpdate([
        {
          table_name: 'sys_user',
          update: [
            {
              password:
                '24dd82970a462b7da6a55dea5022d1312205f561076e2553e48923ba3b1a8d31',
              salt: 'wFwbvuBIHPY7T5qGQytf'
            }
          ],
          where: [
            {
              user_id: this.userId
            }
          ]
        }
      ])
      if (res[0]) {
        return
      }
      let data = res[1]
      if (data && data.code === 0) {
        this.$message.success('重置密码成功')
      } else {
        this.$message.error(data.msg)
      }
    },
    deleteContract (item) {
      this.$confirm('确定删除操作', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.remove(item)
        })
        .catch(() => {})
    },
    async remove (item) {
      let res = await tableDeleted([
        {
          table_name: 'nice_student_contacts',
          where: {
            id: [item.id]
          }
        }
      ])
      if (res[0]) {
        return
      }
      let data = res[1]
      if (data && data.code === 0) {
        this.$message.success('删除联系人成功！')
        if (item.id === this.currentValue) {
          this.currentValue = 0
        }
        this.getStudentDetail()
      } else {
        this.$message.error(data.msg)
      }
    },
    addContract () {
      this.addContractVisible = true
      this.$nextTick(() => {
        this.$refs.addContract.init(this.userId)
      })
    },
    adjustDateHandle (row) {
      this.adjustDateVisible = true
      this.$nextTick(() => {
        this.$refs.adjustDate.init(row, this.userId)
      })
    },
    handleStudyCurrentChange (val) {
      this.studyPagination.pageNum = val
      this.getLearningExperience()
    },
    handleStudySizeChange (val) {
      this.studyPagination.pageSize = val
      this.getLearningExperience()
    },
    handleOrderCurrentChange (val) {
      this.orderPagination.pageNum = val
      this.getOrderListById()
    },
    handleOrderSizeChange (val) {
      this.orderPagination.pageSize = val
      this.getOrderListById()
    },
    handleOrderCurrentChange1 (val) {
      this.orderCodePagination.pageNum = val
      this.getIntegralOrderListById()
    },
    handleOrderSizeChange1 (val) {
      this.orderCodePagination.pageSize = val
      this.getIntegralOrderListById()
    },
    adjustDateSave () {},
    handleRemove () {
      this.detail.head_url = ''
    },
    async uploadImg (e) {
      let formData = new FormData()
      formData.append('file', e.file)
      let res = await ossUpload(formData, 'STUDENGT_PORTRAIT')
      if (res[0]) {
        return
      }
      this.detail.head_url = res[1].data.url
    },
    beforeAvatarUpload (file) {
      const isJPG =
        file.type === 'image/jpeg' ||
        file.type === 'image/png' ||
        file.type === 'image/gif'
      const isLt2M = file.size / 1024 / 1024 < 2
      if (!isJPG) {
        this.$message.error('上传的封面图片只能是 JPG 或 PNG 格式或 GIF 格式!')
      }
      if (!isLt2M) {
        this.$message.error('上传的封面图片大小不能超过 2MB!')
      }
      return isJPG && isLt2M
    },
    viewOrderDetail (val) {
      this.$router.push({
        name: 'order-details',
        query: { id: val.id }
      })
    },
    viewIntegralOrderDetail (val) {
      this.$router.push({
        name: 'integral-order-details',
        query: { order_id: val.id }
      })
    },
    validateMobile (rule, value, callback) {
      if (!this.$valid.isMobile(value)) {
        callback(new Error('手机号格式错误'))
      } else {
        callback()
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.detail {
  margin-bottom: 50px;
}
</style>
